<?php View::display('technic/menu');?>
<!-- .head -->
<header class="head">
	<!-- ."main-bar -->
	<div class="main-bar">
		<div class="container-fluid">
			<div class="row-fluid">
				<div class="span12">
					<h3>
						<i class="icon-wrench"></i> บทความ
					</h3>
				</div>
			</div>
			<!-- /.row-fluid -->
		</div>
		<!-- /.container-fluid -->
	</div>
	<!-- /.main-bar -->
</header>
<!-- /.head -->
<!-- #content -->
<div id="content">
	<!-- .outer -->
	<div class="container-fluid outer">
		<div class="row-fluid">
			<!-- .inner -->
			<div class="span12 inner">
				<!--Begin Datatables-->
				<div class="row-fluid">
					<div class="span12">
						<div class="box">
							<header>
								<div style="padding: 10px">
									<a class="btn btn-success" href="index.php?page=technic/article.add">เพิ่มบทความ</a>
								</div>
							</header>
							<div class="body">
								<table class="table table-bordered dataTable responsive">
									<thead>
										<tr>
											<th>id</th>
											<th>title</th>
											<th></th>
											<th></th>
										</tr>
									</thead>
									<tbody>
									<?php foreach($params['articles'] as $key => $article){?>
										<tr class="list-row" rowId="<?php echo $article['id'];?>">
											<td><?php echo $article['id'];?></td>
											<td><a target="_blank" href="index.php?page=article&id=<?php echo $article['id'];?>"><?php echo $article['title'];?></a></td>
											<td><a href="index.php?page=technic/article.edit&id=<?php echo $article['id'];?>" class="btn btn-warning">แก้ไข</a></td>
											<td><a class="btn btn-danger deltButton">ลบ</a></td>
										</tr>
									<?php }?>
									</tbody>
								</table>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<!--Begin Datatables-->
	</div>
</div>
<div class="clearfix"></div>
<script type="text/javascript">
$(function(){
	var oTable = $('.dataTable').dataTable({"bFilter": false, "bInfo": false, "bSort": false,
		sDom: "<'pull-right'l>t<'row-fluid'<'span6'f><'span6'p>>",
        sPaginationType: "bootstrap",
        oLanguage: {
            "sLengthMenu": "Show _MENU_ entries"
        }
    });

	function delRow(row){
		$(row).fadeOut(function(){
			row = $(row).get(0);
			oTable.fnDeleteRow(oTable.fnGetPosition(row));
		});
	}
	
	$('.list-row')
        .delegate('.deltButton', 'click', function(event){
            if(!window.confirm('ยืนยันการลบ'))
                return false;
            var dTarget = $(event.delegateTarget);
            var id = dTarget.attr('rowId');
            $('.deltButton', dTarget).button('loading');
            $.ajax('index.php?page=technic/article.rest', {
                type: 'DELETE',
                data: {id: id},
                dataType: 'JSON',
                success: function(data){
                    $('.deltButton', dTarget).button('reset');
                    if(typeof data.error == 'undefined'){
                        dTarget.fadeOut('slow', function(){ $(this).remove(); });
                    }
                }
            });
        });
});
</script>